package com.fast.web.common;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 全局异常处理
 * 如果采用这种异常处理方式，则spring-servlet中的SimpleMappingExceptionResolver将不起作用
 * 对异常类型的判断需要写在代码中，故暂时还是先用spring-servlet中统一的异常处理。
 * 
 * @author Tonny Luo
 *
 */
// @ControllerAdvice
public class MvcExceptionHandler {
	private static final Logger log = LoggerFactory.getLogger(MvcExceptionHandler.class);

	/**
	 * 异常处理
	 * 
	 * @param ex
	 * @param request
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public String handleException(Exception ex, HttpServletRequest request) {
		Object[] params = new Object[] { request.getRemoteHost(), request.getRequestURI(), ex.getMessage() };
		log.info("{} host request url {} error is {}", params);
		return "forward:/WEB-INF/jsp/error/500.jsp";
	}
}
